package com.kate.mall.promotion.service.impl;

import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kate.mall.common.utils.PageUtils;
import com.kate.mall.common.utils.Query;

import com.kate.mall.promotion.dao.GrouponRulesDao;
import com.kate.mall.promotion.entity.GrouponRulesEntity;
import com.kate.mall.promotion.service.GrouponRulesService;


@Service("grouponRulesService")
public class GrouponRulesServiceImpl extends ServiceImpl<GrouponRulesDao, GrouponRulesEntity> implements GrouponRulesService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<GrouponRulesEntity> page = this.page(
                new Query<GrouponRulesEntity>().getPage(params),
                generatorQueryWrapper(params)
        );

        return new PageUtils(page);
    }
    public QueryWrapper generatorQueryWrapper(Map<String, Object> params) {//is_hot=1
        QueryWrapper<GrouponRulesEntity> queryWrapper = new QueryWrapper<>();
        if (params.containsKey("goods_id")) {
            //where is_hot=1
            queryWrapper.lambda().eq(GrouponRulesEntity::getGoodsId, Integer.parseInt((String) params.get("goods_id")));
        }
        queryWrapper.lambda().le(GrouponRulesEntity::getExpireTime, LocalDateTime.now());
        return queryWrapper;
    }

}